/*
 * WindowEvent.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.events;

import com.cute4j.swing.Window;
import com.cute4j.swing.WindowConstants;

/**
 * Window Event.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class WindowEvent extends ComponentEvent {

// Public Static Fields. -------------------------------------------------------

  /**
   * The window opened id.
   */
  public static final int WINDOW_OPENED = 200;

  /**
   * The window closing id.
   */
  public static final int WINDOW_CLOSING = 201;

  /**
   * The window closed id.
   */
  public static final int WINDOW_CLOSED = 202;

  /**
   * The window activated id.
   */
  public static final int WINDOW_ACTIVATED = 205;

  /**
   * The window deactivated id.
   */
  public static final int WINDOW_DEACTIVATED = 206;

  /**
   * The window focus gained id.
   */
  public static final int WINDOW_GAINED_FOCUS = 207;

  /**
   * The window focus lost id.
   */
  public static final int WINDOW_LOST_FOCUS = 208;

  /**
   * The window state changed id.
   */
  public static final int WINDOW_STATE_CHANGED = 209;

// Private Static Fields. ------------------------------------------------------

  private static final long serialVersionUID = -2958473444582454421L;

// Private Fields. -------------------------------------------------------------

  private int oldState;
  private int newState;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new WindowEvent object.
   *
   * @param source the source of the event
   * @param id the event type
   * @param oldState the old state of the window
   * @param newState the new state of the window
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public WindowEvent(Window source, int id, int oldState, int newState) {
    super(source, id);
    this.oldState = oldState;
    this.newState = newState;
  }

  /**
   * Constructs new WindowEvent object.
   *
   * @param source the source of the event
   * @param id the event type
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public WindowEvent(Window source, int id) {
    this(source, id, 0, 0);
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns the source window of the event.
   *
   * @return the source window of the event
   */
  public Window getWindow() {
    return (Window)source;
  }

  /**
   * Returns old window state.
   *
   * @return old window state
   */
  public int getOldState() {
    return oldState;
  }

  /**
   * Returns new window state.
   *
   * @return new window state
   */
  public int getNewState() {
    return newState;
  }

// Protected Methods. ----------------------------------------------------------

  /**
   * Returns string representation of the window state.
   *
   * @param state the window state
   *
   * @return string representation of the window state
   */
  protected String stateString(int state) {
    switch (state) {
      case WindowConstants.NORMAL:
        return "NORMAL";
      case WindowConstants.ICONIFIED:
        return "ICONIFIED";
      case WindowConstants.MAXIMIZED:
        return "MAXIMIZED";
      case WindowConstants.FULL_SCREEN:
        return "FULL_SCREEN";
      default:
        return "UNKNOWN";
    }
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public String paramString() {
    String paramString;
    switch (id) {
      case WINDOW_OPENED:
        paramString = "WINDOW_OPENED";
        break;
      case WINDOW_CLOSING:
        paramString = "WINDOW_CLOSING";
        break;
      case WINDOW_CLOSED:
        paramString = "WINDOW_CLOSED";
        break;
      case WINDOW_ACTIVATED:
        paramString = "WINDOW_ACTIVATED";
        break;
      case WINDOW_DEACTIVATED:
        paramString = "WINDOW_DEACTIVATED";
        break;
      case WINDOW_GAINED_FOCUS:
        paramString = "WINDOW_GAINED_FOCUS";
        break;
      case WINDOW_LOST_FOCUS:
        paramString = "WINDOW_LOST_FOCUS";
        break;
      case WINDOW_STATE_CHANGED:
        paramString = "WINDOW_STATE_CHANGED";
        break;
      default:
        paramString = "unknown type";
    }
    return paramString + ",oldState=" + stateString(getOldState()) +
           ",newState=" + stateString(getNewState());
  }

}
